package utils

import (
	"fmt"
	"gitee.com/chejiangyi/bsfgo/core/base2"
	"time"
)

var DateUtil = &DateUtilTool{}

type DateUtilTool struct{}

func TimeFormatString(time time.Time, format string) string {
	if time.IsZero() {
		return ""
	}
	return time.Format(base2.DateFormat{}.ConvertTimeFormat(format))
}

func TimeFormatString2(t time.Time) string {
	now := time.Now()
	duration := now.Sub(t)

	switch {
	case duration < time.Minute:
		// 1分钟内显示"最近n秒"
		seconds := int(duration.Seconds())
		return fmt.Sprintf("近%d秒内", seconds)
	case duration < time.Hour:
		// 1小时内显示"最近n分钟"
		minutes := int(duration.Minutes())
		return fmt.Sprintf("近%d分钟内", minutes)
	default:
		// 超过24小时显示完整时间格式
		return t.Format("2006-01-02 15:04:05")
	}
}
